/* 
 * File:   Agent.h
 * Author: flai0014
 *
 * Created on March 30, 2012, 11:49 AM
 */

#ifndef _AGENT_H
#define	_AGENT_H
#include "Thread.h"
#include <pthread.h>
#include <cstdlib>
#include "Enviroment.h"
#include "EnvCell.h"
#include "Particle.h"
#define PROB 3
#define DIRECTIONS 4

class Enviroment;

using namespace std;

class Agent : public Thread{
public:
    Agent(int agentNum);
    virtual ~Agent();
    
    /* Overridden stop function for ending gracfully */
    void stop();
private:
    /* Run function called when the thread is started */
    void* run(void * attb);
    
    /* Checks the cell and the agent for a particle and drops or picks up on a
     * 3/10 chance
     */
    void checkForParticile();
    
    /* Function for starting the pickup process obtains lock from cell or
     * waits for lock to open up
     */
    void startPickup();
    
    /* This ends the pickup process and releases the lock on the cell  */
    void endPickup(); 
    
    /* This starts the drop process and obtains the lock on the cell  */
    void startDrop();
    
    /* This ends the drop process and releases the lock on the cell  */
    void endDrop();
    
    /* Moves the agent one square at random by calling to the enviroment
     * to return the new location
     */
    void move(); 
    
    /* This does the drop process and puts the particle in the cell  */
    void dropItem();
    
    /* this picks up a particle from a cell  */
    void pickUpItem(); 
    
    /* This is a check in function for the agents when they find a wait flag */
    void checkIn();
    
    Agent* m_agent;
    EnvCell* m_cell;
    Particle* m_particle;
    bool stopFlag;
    bool hasParticle;
    int location;
    int m_agentID;
    static pthread_cond_t condition_var;
};




#endif	/* AGENT_H */

